<?php

/**
 * Singleton pattern implementation.
 */
abstract class Singleton
{
  private static $instance = array();

  protected function __construct() {

  }
  /**
   * @param string ClassName Name of the class to be instantiated.
   */
  protected static function &getSingleton($className)
  {
    if(!isset(self::$instance[$className]))
    {
      self::$instance[$className] = new $className;
    }
    return self::$instance[$className];
  }

  /**
   * To be implemented by extending class.
   */
  abstract public static function &factory(); 
  /* { return parent::getSingleton(__CLASS__); } */    
}

?>
